package com.hspedu.com.jdbc.practice;

import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
import java.util.Scanner;

/**
 * @author DL5O
 * @version 1.0
 * 查询记录
 */
public class Practice04 {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Properties properties = new Properties();
        properties.load(new FileReader("src\\jdbc.properties"));
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
        String url = properties.getProperty("url");
        String driver = properties.getProperty("driver");

        //1.注册驱动
        Class.forName(driver);
        //2.得到连接
        Connection connection = DriverManager.getConnection(url, user, password);//进行注册

        String sql = "select * from admin";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery();
        while(resultSet.next()){
            String name = resultSet.getString("name");
//            Object name1 = resultSet.getObject("name");
            String pwd = resultSet.getString("pwd");
            System.out.print(name + "\t" + pwd + "\t");
            System.out.println();
        }
        preparedStatement.close();
        connection.close();
    }
}
